import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [

  // login part
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },
  {
    path: '/register',
    component: () => import('@/views/login/register/index'),
    hidden: true,
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },
  {
    path: '/forgetpassword',
    component: () => import('@/views/login/forgetPassword/index'),
    hidden: true,
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },

  // exception part
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },
  {
    path: '/',
    redirect: '/mainpage',
    hidden: true,
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },
  {
    path: '/mainpage',
    component: Layout,
    meta: { title: '首页', icon: 'el-icon-s-home',visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] },
    children: [{
      path: 'superadmin',
      name: 'SuperAdmin',
      component: () => import('@/views/mainpage/admin/index'),
      meta: { title: '管理员', icon: 'el-icon-s-home', visiable: false, roles: ['SuperAdmin'] }
    },{
      path: 'manager',
      name: 'Manager',
      component: () => import('@/views/mainpage/manager/index'),
      meta: { title: '经理', icon: 'el-icon-s-home', visiable: false, roles: ['Manager'] }
    },{
      path: 'counter',
      name: 'Counter',
      component: () => import('@/views/mainpage/counter/index'),
      meta: { title: '柜员', icon: 'el-icon-s-home', visiable: false, roles: ['Counter'] }
    },{
      path: 'user',
      name: 'User',
      component: () => import('@/views/mainpage/user/index'),
      meta: { title: '用户', icon: 'el-icon-s-home', visiable: false, roles: ['User'] }
    }]
  },
  {
    path: '/employee',
    component: Layout,
    name: 'Employee',
    meta: { visiable: false, icon: 'el-icon-user',roles: ['SuperAdmin', 'Manager'] },
    children: [
      {
        path: 'management',
        name: 'Management',
        component: () => import('@/views/employee/index'),
        meta: { title: '员工管理', icon: 'el-icon-user', visiable: false, roles: ['SuperAdmin', 'Manager'] }
      }
    ]
  },
  {
    path: '/deposit',
    component: Layout,
    name: 'Deposit',
    redirect: '/deposit/management',
    meta: { title: '存款', icon: 'el-icon-money', visiable: false, roles: ['Manager', 'Counter','User'] },
    children: [
      {
        path: 'management',
        name: 'Management',
        component: () => import('@/views/deposit/management/index'),
        meta: { title: '存款历史', icon: 'el-icon-money', visiable: false, roles: ['Manager', 'Counter'] }
      },
      {
        path: 'cash',
        name: 'Cash',
        component: () => import('@/views/deposit/cash/index'),
        meta: { title: '现金存款', icon: 'el-icon-s-finance', visiable: false, roles: ['Counter'] }
      },
      {
        path: 'personal',
        name: 'PersonalDeposit',
        component: () => import('@/views/deposit/personal/index'),
        meta: { title: '个人存款', icon: 'el-icon-user-solid', visiable: false, roles: ['User'] }
      }
    ]
  },
  {
    path: '/loan',
    component: Layout,
    NAME: 'Loan',
    meta: { title: '贷款', icon: 'el-icon-money', visiable: false, roles: ['Manager', 'Counter','User'] },
    children: [
      {
        path: 'management',
        name: 'Management',
        component: () => import('@/views/loan/management/index'),
        meta: { title: '贷款管理', icon: 'el-icon-money', visiable: false, roles: ['Manager', 'Counter'] }
      },
      {
        path: 'personal',
        name: 'PersonalLoan',
        component: () => import('@/views/loan/personal/index'),
        meta: { title: '个人贷款', icon: 'el-icon-user-solid', visiable: false, roles: ['User'] }
      },
      {
        path: 'mortgage',
        name: 'Mortgage',
        component: () => import('@/views/loan/mortgage/index'),
        meta: { title: '抵押物贷款', icon: 'el-icon-user-solid', visiable: false, roles: ['User'] }
      },
      {
        path: 'credit',
        name: 'Credit',
        component: () => import('@/views/loan/credit/index'),
        meta: { title: '信用贷款', icon: 'el-icon-user-solid', visiable: false, roles: ['User'] }
      }
    ]
  },
  {
    path: '/transfer',
    component: Layout,
    name: 'Transfer',
    meta: {
      title: '转账', icon: 'el-icon-money', visiable:
        false, roles: ['Manager', 'Counter', 'User']
    },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/transfer/history/index'),
        meta: { title: '转账历史', icon: 'el-icon-time', visiable: false, roles: ['Manager', 'Counter'] }
      },
      {
        path: 'cash',
        name: 'Cash',
        component: () => import('@/views/transfer/cash/index'),
        meta: { title: '现金转账', icon: 'el-icon-s-finance', visiable: false, roles: ['Counter'] }
      },
      {
        path: 'online',
        name: 'Online',
        component: () => import('@/views/transfer/online/index'),
        meta: { title: '在线转账', icon: 'el-icon-monitor', visiable: false, roles: ['User'] }
      },
      {
        path: 'personal',
        name: 'PersonalTransfer',
        component: () => import('@/views/transfer/personal/index'),
        meta: { title: '个人转账', icon: 'el-icon-user-solid', visiable: false, roles: ['User'] }
      }
    ]
  },


  {
    path: '/user',
    component: Layout,
    name: 'User',
    meta: {
      title: '用户',
      icon: 'el-icon-s-custom',
      visiable: false,
      roles: ['SuperAdmin', 'Manager','User']
    },
    children: [
      {
        path: 'loanlist',
        component: () => import('@/views/user/loanlist/index'), // Parent router-view
        name: 'LoanList',
        meta: { title: '贷款名单', icon: 'el-icon-user',visiable: false, roles: ['SuperAdmin', 'Manager'] }
      },
      {
        path: 'depositlist',
        component: () => import('@/views/user/depositlist/index'), // Parent router-view
        name: 'DepositList',
        meta: { title: '存款名单', icon: 'el-icon-user',visiable: false, roles: ['SuperAdmin', 'Manager'] }
      },
      {
        path: 'clientlist',
        component: () => import('@/views/user/clientlist/index'), // Parent router-view
        name: 'ClientList',
        meta: { title: '客户名单', icon: 'el-icon-user',visiable: false, roles: ['SuperAdmin', 'Manager'] }
      },{
        path: '/accounts',
        name: 'Accounts',
        component: () => import('@/views/user/accounts/index'),
        meta: { title: '账户管理', icon: 'el-icon-bank-card', visiable: false, roles: ['User'] }
      }
    ]
  },
  {
    path: '/notice',
    component: Layout,
    name: 'Notice',
    hidden: true,
    meta: { visiable: false, icon: 'el-icon-message-solid',roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] },
    children: [
      {
        path: '/notice',
        name: 'Notice',
        component: () => import('@/views/notice/index.vue'),
        meta: { title: '信箱', icon: 'el-icon-message-solid', visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    name: 'System',
    hidden: true,
    meta: { visiable: false, icon: 'el-icon-message-solid',roles: ['SuperAdmin', 'Manager'] },
    children: [
      {
        path: '/system',
        name: 'System',
        component: () => import('@/views/system/index.vue'),
        meta: { title: '系统信息', icon: 'el-icon-chat-dot-round', visiable: false, roles: ['SuperAdmin', 'Manager'] }
      }
    ]
  },
  {
    path: '/import',
    component: Layout,
    name: 'Import',
    hidden: true,
    meta: { visiable: false, icon: 'el-icon-message-solid',roles: ['SuperAdmin'] },
    children: [
      {
        path: '/import',
        name: 'Import',
        component: () => import('@/views/import/index.vue'),
        meta: { title: '导入', icon: 'el-icon-chat-dot-round', visiable: false, roles: ['SuperAdmin'] }
      }
    ]
  },
  {
    path: '/chat',
    component: Layout,
    name: 'Chat',
    meta: { visiable: false, icon: 'el-icon-message-solid',roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] },
    children: [
      {
        path: '/chat',
        name: 'Chat',
        component: () => import('@/views/chat/index.vue'),
        meta: { title: '聊天室', icon: 'el-icon-chat-dot-round', visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
      }
    ]
  },
  // special
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link', visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
      }
    ],
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },

  // 404 page must be placed at the end !!!
  {
    path: '*', redirect: '/404', hidden: true,
    meta: { visiable: false, roles: ['SuperAdmin', 'Manager', 'Counter', 'User'] }
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
